<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>忘记密码</title>
    <link rel="stylesheet" href="/static/css/hui.css">
</head>

<body>
    <header class="hui-header">
        <div id="hui-back"></div>
        <h1>忘记密码</h1>
    </header>
    <div class="hui-wrap">
        <form style="padding:28px 10px;" class="hui-form" id="form1" enctype="multipart/form-data">

            <!--  -->
            <div class="hui-form-items">
                <div class="hui-form-items-title">手机号码</div>
                <input type="number" class="hui-input" placeholder="请输入手机号码" id="account" name="account" checktype="phone" checkmsg="手机号码格式错误">
            </div>
            <div class="hui-form-items">
                <div class="hui-form-items-title">昵称</div>
                <input type="text" class="hui-input hui-input-clear" placeholder="请输入昵称" id="nickname" name="nickname" checktype="string"
                    checkdata="2,10" checkmsg="昵称应为2-10个字符">
            </div>
            <div class="hui-form-items">
                <div class="hui-form-items-title">新密码</div>
                <input type="password" class="hui-input hui-pwd-eye" placeholder="登录密码" checktype="passWord" id="pwd" checkmsg="密码应由字母和数字组成的6-12个字符">
                <div class="hui-pwd-eyes" onclick="hui.eyesChange(this);"></div>
            </div>
            <div class="hui-form-items">
                <div class="hui-form-items-title">确认密码</div>
                <input type="password" class="hui-input hui-pwd-eye" placeholder="确认密码" checktype="sameWithId" checkdata="pwd" checkmsg="两次密码不一致">
                <div class="hui-pwd-eyes" onclick="hui.eyesChange(this);"></div>
            </div>
            <div style="padding:15px 8px;">
                <button type="button" class="hui-button hui-button-large hui-primary" id="subBtn">提交</button>
            </div>
        </form>
    </div>


    <script type="text/javascript" src="/static/js/hui.js"></script>
    <script type="text/javascript" src="/static/js/hui-form.js"></script>

    <script>
        hui("#subBtn").click(function (e) {
            //表单验证
            hui.formInit();
            var res = huiFormCheck('#form1');
            //提交
            if (res) {
                var account = hui('#account').val();
                var nickname = hui('#nickname').val();
                var paw = hui('#pwd').val();
                hui.ajax({
                    url: 'http://127.0.0.1:5000/forgetPW/',
                    data: {
                        account: account,
                        nickname: nickname,
                        paw: paw
                    },
                    type: 'POST',
                    cache: false,
                    'backType': "JSON",
                    beforeSend: function () { hui.loading(); },
                    complete: function () { hui.closeLoading(); },
                    success: function (data) {
                        console.log(data)
                        if (data.code != 0) {
                            // hui.iconToast(data.message);
                            hui.alert('密码已修改，请使用新密码登陆', '好的', function () {
                                window.location.href = "http://127.0.0.1:5000/login/";
                            })


                        } else {
                            hui.iconToast(data.message, 'error');


                        }

                    }

                })
            }

        });
    </script>
</body>

</html>